//
//  ViewController.m
//  环信即时通讯总结
//
//  Created by 曦胜 on 2018/4/27.
//  Copyright © 2018年 BaoBeiKeJi. All rights reserved.
//

#import "ViewController.h"
#import <Hyphenate/Hyphenate.h>
#import "EaseMessageViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}


- (IBAction)registUserBtnClicked:(id)sender {
    EMError *error = [[EMClient sharedClient] registerWithUsername:@"123456" password:@"123456"];
    if (error==nil) {
        NSLog(@"注册成功");
    }
    
}

- (IBAction)userLoginBtnClicked:(id)sender {
    [[EMClient sharedClient] loginWithUsername:@"123456"
                                      password:@"123456"
                                    completion:^(NSString *aUsername, EMError *aError) {
                                        if (!aError) {
                                            NSLog(@"登录成功");
                                        } else {
                                            NSLog(@"登录失败");
                                        }
                                    }];
    
    
    //设置为自动登录
    EMError *error = [[EMClient sharedClient] loginWithUsername:@"123456" password:@"123456"];
    if (!error)
    {
        [[EMClient sharedClient].options setIsAutoLogin:YES];
    }
    
}


- (IBAction)starChatBtnClicked:(id)sender {
    
//    初始化单聊页面
    
    //环信ID:@"8001"
    //聊天类型:EMConversationTypeChat
    EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"123460" conversationType:EMConversationTypeChat];
    [self presentViewController:chatController animated:YES completion:^{
        
    }];
    
}


- (IBAction)addFriendBtnClicked:(id)sender {
//    快速集成好友功能
//
//    首先需要完成快速集成单聊上述步骤。
//
//    添加好友
    
//    [[EMClient sharedClient].contactManager addContact:@"123460"
//                                               message:@"我想加您为好友"
//                                            completion:^(NSString *aUsername, EMError *aError) {
//                                                if (!aError) {
//                                                    NSLog(@"邀请发送成功");
//                                                }
//                                            }];
    
    //同意好友申请
//    [[EMClient sharedClient].contactManager approveFriendRequestFromUser:@"123456"
//                                                              completion:^(NSString *aUsername, EMError *aError) {
//                                                                  if (!aError) {
//                                                                      NSLog(@"同意好友成功");
//                                                                  }
//                                                              }];
    
    //拒绝好友申请
//    [[EMClient sharedClient].contactManager declineFriendRequestFromUser:@"8001"
//                                                              completion:^(NSString *aUsername, EMError *aError) {
//                                                                  if (!aError) {
//                                                                      NSLog(@"拒绝好友成功");
//                                                                  }
//                                                              }];
    
    
}

- (IBAction)getAllFriendBtnClicked:(id)sender {
//    获取好友
    
    //从服务器获取所有的好友
    [[EMClient sharedClient].contactManager getContactsFromServerWithCompletion:^(NSArray *aList, EMError *aError) {
        if (!aError) {
            NSLog(@"获取成功");
        }
    }];
    //从数据库获取所有的好友
    NSArray *userlist = [[EMClient sharedClient].contactManager getContacts];
    
    NSLog(@"好友列表内容是%@",userlist);
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
